var error_msg_520 = ""; function validate_email_520(mail) { if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail)) { return (true); } error_msg_520 = "Имэйл хаягаа зөв оруулна уу"; return (false); } function getCookie_520(cname) { var name_520 = cname + "="; var decodedCookie_520 = decodeURIComponent(document.cookie); var ca_520 = decodedCookie_520.split(';'); for(var i = 0; i < ca_520.length; i++) { var c_520 = ca_520[i]; while (c_520.charAt(0) == ' ') { c_520 = c_520.substring(1); } if (c_520.indexOf(name_520) == 0) { return c_520.substring(name_520.length, c_520.length); } } return ""; } function subscribe_submit_520(){ var form_520 = document.querySelector('#subscribe-form-520'); var data_520 = new FormData(form_520); var url_520 = "/api.php/subscription/save?site_id=524&id=520" + '&cookie_id=' + getCookie_520("cookie_id") + '&short_cookie_id=' + getCookie_520("short_cookie_id"); var xhr_520 = new XMLHttpRequest(); if (window.XMLHttpRequest) { // Mozilla, Safari, ... var xhr_520 = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE var xhr_520 = new ActiveXObject("Microsoft.XMLHTTP"); } xhr_520.open('POST', url_520, true); xhr_520.onload = function () { /* do something to response */ console.log(this.responseText); document.getElementById("subscription-form-container-520").innerHTML = this.responseText; }; var valid_520 = 1; if(form_520.querySelector('input[name="subscriber[name]"]')){ if(form_520.querySelector('input[name="subscriber[name]"]').value.trim().length > 0){ }else{ valid_520 = 0; form_520.querySelector('input[name="subscriber[name]"]').setAttribute("style", "border-color: red;"); } } if(form_520.querySelector('input[name="subscriber[email]"]')){ if(form_520.querySelector('input[name="subscriber[email]"]').value.trim().length > 0){ }else{ valid_520 = 0; form_520.querySelector('input[name="subscriber[email]"]').setAttribute("style", "border-color: red;"); } } if(form_520.querySelector('input[name="subscriber[phone]"]')){ if(form_520.querySelector('input[name="subscriber[phone]"]').value.trim().length > 0){ }else{ valid_520 = 0; form_520.querySelector('input[name="subscriber[phone]"]').setAttribute("style", "border-color: red;"); } } if(form_520.querySelector('input[name="subscription[company_name]"]')){ if(form_520.querySelector('input[name="subscription[company_name]"]').value.trim().length > 0){ }else{ valid_520 = 0; form_520.querySelector('input[name="subscription[company_name]"]').setAttribute("style", "border-color: red;"); } } if(form_520.querySelector('input[name="subscription[company_position]"]')){ if(form_520.querySelector('input[name="subscription[company_position]"]').value.trim().length > 0){ }else{ valid_520 = 0; form_520.querySelector('input[name="subscription[company_position]"]').setAttribute("style", "border-color: red;"); } } if(form_520.querySelector('input[name="subscription[title]"]')){ if(form_520.querySelector('input[name="subscription[title]"]').value.trim().length > 0){ }else{ valid_520 = 0; form_520.querySelector('input[name="subscription[title]"]').setAttribute("style", "border-color: red;"); } } if(form_520.querySelector('textarea[name="subscription[body]"]')){ if(form_520.querySelector('textarea[name="subscription[body]"]').value.trim().length > 0){ }else{ valid_520 = 0; form_520.querySelector('textarea[name="subscription[body]"]').setAttribute("style", "border-color: red;"); } } if(valid_520 == 0){ error_msg_520 = "Талбаруудыг бүрэн бөглөнө үү!"; } if(!validate_email_520(form_520.querySelector('input[name="subscriber[email]"]').value)){ form_520.querySelector('input[name="subscriber[email]"]').style="border-color: red;"; valid_520 = 0; }else{ } if(valid_520){ document.querySelector('#subscribe-form-520').style.display = "none"; document.querySelector('#subscription-form-loading-520').style.display = "inline"; xhr_520.send(data_520); }else{ alert(error_msg_520); } } // function postRequest_520(strURL) { var xmlHttp_520; if (window.XMLHttpRequest) { // Mozilla, Safari, ... var xmlHttp_520 = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE var xmlHttp_520 = new ActiveXObject("Microsoft.XMLHTTP"); } xmlHttp_520.open('POST', strURL, true); xmlHttp_520.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlHttp_520.onreadystatechange = function() { if (xmlHttp_520.readyState == 4) { updatepage_520(xmlHttp_520.responseText); } } xmlHttp_520.send(strURL); } // function updatepage_520(str){ document.getElementById("subscription-form-container-520").innerHTML = str; } //'//elitetourmongolia.com' + var get_url_520 = '/api.php/subscription/renderform?site_id=524' + '&id=520' + '&placeholder[subscriber][name]=First Name, Last Name&placeholder[subscriber][email]=Agency: Email&placeholder[subscriber][phone]=Agency: Phone number&placeholder[subscription][website]=Agency: website&placeholder[subscription][company_name]=Agency: Name &placeholder[subscription][company_position]=Agency Market (inbound or outbound)&placeholder[subscription][title]=Agency : location&placeholder[subscription][body]=if any request&send=Submit' ; postRequest_520(get_url_520);